FROM centos:7

# CentOS 7 EOL is June 30, 2024, but the repos remain in the vault.
RUN cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak && \
    curl -k -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-AltArch-7.repo && \
    yum clean all && \
    yum makecache

RUN yum update -y
RUN yum install -y libwebkit2gtk-4.0-dev \
        build-essential \
        ca-certificates \
        curl \
        wget \
        file \
        libssl-dev \
        libgtk-3-dev \
        libayatana-appindicator3-dev \
        librsvg2-dev \
        make \
        gcc \
        gcc-c++ \
        perl-core \
        perl-devel \
        openssl-devel \
        zlib-devel \
        git

# 需要确保有abcert.sh脚本,用于添加证书。
COPY abcert.sh /tmp
RUN sh /tmp/abcert.sh

# Download and install NodeJS
# ENV NODEJS_VERSION=v20.12.2
# RUN curl -k -sL "https://nodejs.org/dist/${NODEJS_VERSION}/node-${NODEJS_VERSION}-linux-arm64.tar.xz" | tar -xJ
# RUN mv "node-${NODEJS_VERSION}-linux-arm64" "/node"
# ENV PATH="/node/bin:${PATH}"
# RUN npm i -g pnpm

# Install Rust
ENV RUST_VERSION=1.87.0
ENV TARGET_ARCH=aarch64-unknown-linux-gnu
RUN curl -k -sSf -O https://static.rust-lang.org/dist/rust-${RUST_VERSION}-${TARGET_ARCH}.tar.gz
RUN tar -xzf rust-${RUST_VERSION}-${TARGET_ARCH}.tar.gz
RUN cd rust-${RUST_VERSION}-${TARGET_ARCH} && ./install.sh
RUN rm -rf rust-${RUST_VERSION}-${TARGET_ARCH}.tar.gz rust-${RUST_VERSION}-${TARGET_ARCH}
RUN rustc --version && cargo --version

# Replace Crates-io
RUN mkdir -p /root/.cargo \
&& echo '[source.crates-io]' > /root/.cargo/config.toml  \
&& echo 'replace-with = "rsproxy-sparse"' >> /root/.cargo/config.toml \
&& echo '[source.rsproxy]' >> /root/.cargo/config.toml \
&& echo 'registry = "https://rsproxy.cn/crates.io-index"' >> /root/.cargo/config.toml \
&& echo '[source.rsproxy-sparse]' >> /root/.cargo/config.toml \
&& echo 'registry = "sparse+https://rsproxy.cn/index/"' >> /root/.cargo/config.toml \
&& echo '[registries.rsproxy]' >> /root/.cargo/config.toml \
&& echo 'index = "https://rsproxy.cn/crates.io-index"' >> /root/.cargo/config.toml \
&& echo '[net]' >> /root/.cargo/config.toml \
&& echo 'git-fetch-with-cli = true' >> /root/.cargo/config.toml \
&& echo '[http]' >> /root/.cargo/config.toml \
&& echo 'check-revoke = false' >> /root/.cargo/config.toml

RUN echo "insecure" > ~/.curlrc
RUN git config --global http.sslverify false

# Verify Edition
ENV EDITION=innersource

# Vendor and Build
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
ENV CARGO_HTTP_CHECK_REVOKE=false
ENV CARGO_HTTP_SSL_VERIFY=false
ENV SCRIPT="cargo dev vendor && cargo dev dist --cli"
RUN mkdir /scripts && touch /scripts/command.sh && chmod +x /scripts/command.sh
RUN echo 'pwd && ls -al' >> /scripts/command.sh
RUN echo 'sh -x -c "$SCRIPT"' >> /scripts/command.sh